/* eslint-disable eqeqeq */
import actionInfo from '../action'
import { productdirectionAdd, productdirectionQuery } from '../service/productdirectionService'

function productdirectionInfoReducer(state = { productdirectionList: [] }, action) {
    switch (action.type) {
        case actionInfo.productdirection.ADD:
            return { productdirectionList: [...state.productdirectionList, action.payload] }
        case actionInfo.productdirection.QUERY:
            return { productdirectionList: action.payload }
        default:
            return state
    }
}
export const asyncProductdirectionQuery = (params) => async (dispatch) => {
    let { data } = await productdirectionQuery(params);//做异步请求
    dispatch(productdirectionInfoQuery(data.msg));//
}
const productdirectionInfoQuery = (payload) => {
    return {
        type: actionInfo.productdirection.QUERY,
        payload
    }
}
export const asyncProductdirectionAdd = (params) => async (dispatch) => {
    let { data } = await productdirectionAdd(params);//做异步请求
    if (data.code == 1) {
        dispatch(productdirectionInfoAdd(...data.msg));
    }
}
const productdirectionInfoAdd = (payload) => {
    return {
        type: actionInfo.productdirection.ADD,
        payload
    }
}
export default productdirectionInfoReducer